#include "ZModuleSettings.h"

ZModuleSettings::ZModuleSettings()
{
    name = "";
    heartbeatInterval = -1;
    pingInterval = -1;
    alias = "";
}

ZModuleSettings::ZModuleSettings(const QString &name, int hbeatInterval, int pingInterval, const QString &alias)
{
    this->name = name;
    this->heartbeatInterval = hbeatInterval;
    this->pingInterval = pingInterval;
    this->alias = alias;
}

ZModuleSettings::ZModuleSettings(const ZModuleSettings &other)
{
    this->name = other.name;
    this->heartbeatInterval = other.heartbeatInterval;
    this->pingInterval = other.pingInterval;
    this->alias = other.alias;
    devices = other.devices;
}


ZModuleSettings& ZModuleSettings::operator =(const ZModuleSettings& other)
{
    this->name = other.name;
    this->heartbeatInterval = other.heartbeatInterval;
    this->pingInterval = other.pingInterval;
    this->alias = other.alias;
    devices = other.devices;
    return *this;
}

QString ZModuleSettings::toString() const
{
    QString rslt = "["+name+"] ";
    rslt += "ping="+QString::number(getPingInterval()) + " ";
    rslt += "hbeat="+QString::number(getHeartbeatInterval()) + "\n";
    for(int i = 0; i <  devices.count(); i++) {
        rslt += "\t"+devices.at(i)+"\n";
    }
    return rslt;
}

ZModuleSettings ZModuleSettings::defaultSettings()
{
    return ZModuleSettings("default", 5, 2, "");
}


bool ZModuleSettings::isValid() const
{
   return (!name.isEmpty() && heartbeatInterval > 0 && pingInterval > 0);
}
